/**
 * @author        Nicolas Bottarini <nicolasbottarini@gmail.com>, 404 <http://www.proyecto404.com>
 * @version       $Rev: 3 $
 * @lastrevision  $Date: 2011-09-12 16:45:37 +0000 (Mon, 12 Sep 2011) $	 
 */
package com.proyecto404.core {
	import com.proyecto404.core.collections.Dictionary;
	import com.proyecto404.core.collections.List;
	import com.proyecto404.core.exception.InvalidOperationException;

	public class TranslationManager extends BaseObject {
		private var _translations:Dictionary;
		private var _currentLanguage:String;
		
		public function TranslationManager(currentLanguage:String) {
			super();
			_translations = new Dictionary();
			_currentLanguage = currentLanguage;
		}
		
		public function addTranslation(language:String, id:String, text:String):void {
			if (!_translations.containsKey(language)) {
				_translations.add(language, new Dictionary());
			}
			if (Dictionary(_translations.get(language)).containsKey(id)) {
				throw new InvalidOperationException("Duplicate key with id: " + id); 
			}
			
			Dictionary(_translations.get(language)).add(id, text);
		}
		
		public function get currentLanguage():String {
			return _currentLanguage;
		}
		
		public function getText(id:String):String {
			if (!_translations.containsKey(_currentLanguage)) {
				throw new InvalidOperationException("Invalid Current Language: " + _currentLanguage);
			}
			
			if (!Dictionary(_translations.get(_currentLanguage)).containsKey(id)) {
				throw new InvalidOperationException("Invalid Translation id: " + id);
			}

			return Dictionary(_translations.get(_currentLanguage)).get(id);
		}
 	}
}